#include "btos.h"

//
int8_t binToStr(uint8_t *fileAddr)
{
    int readLen = 0;
    FILE *file = NULL;
    file = fopen(fileAddr, "rb");
    if (file == NULL)
    {
        printf("MAIN open file fail\n");
        return -1;
    }

    fseek(file, 0, SEEK_SET);

    uint8_t buff[50] = {0};

    readLen = fread(&buff, 1, sizeof(buff), file);
    // printf("%d\n", readLen);

    // 拆解文件结构
    do
    {

        for (int i = 0; i < readLen; i++)
        {
            printf("%02X", buff[i]);
        }
        readLen = fread(&buff, 1, sizeof(buff), file);

        // printf("%d\n", readLen);
        if (readLen <= 0)
        {
            break;
        }

    } while (1);

    // printf("parse ok!\n");
    fclose(file);
    return 0;
}

int main(int argc, char *argv[])
{
    // printf("param count %d\n", argc);
    // for (int i = 0; i < argc; i++)
    // {
    //     printf("param[%d] %s\n", i, argv[i]);
    // }

    if (argc < 2)
    {
        printf("This tool is only used to parse bin files, and is very basic, for reference only\n");
        printf("Usage is as follows: *.exe *.bin\n");
        return 0;
    }

    if ((strcmp(argv[1], "help") == 0) || (strcmp(argv[1], "-h") == 0))
    {
        printf("This tool is only used to parse bin files, and is very basic, for reference only\n");
        printf("Usage is as follows: *.exe *.bin\n");
        return 0;
    }

    binToStr(argv[1]);
    return 0;
}
